const express = require("express");
//const mongoose = require('mongoose');
const bodyParser = require("body-parser");
const app = express();
//引入passport
const passport = require("passport");

//引入user.js
const users = require("./routers/api/users");

//引入Profile.js
const profiles = require("./routers/api/profiles");

// DB config
//const db = require("./config/keys").mongoURI;

//Connect to mongodb
//mongoose.connect("db").then(()=>{
//  console.log("MongoDB Connected");//success
//}).catch(err=>{
//console.log(err);//err
//})





//使用body-parser中间件
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());

//passport初始化
app.use(passport.initialize());

require("./config/passport")(passport);


//app.get("/",(req,res)=>{
//  res.send("Hello World");
//})

//使用routers
app.use("/api/users",users);
app.use("/api/profiles",profiles);

const port = process.env.PORT || 5000;

app.listen(port,()=>{
  console.log('Server id running on port ${port}');
})